package com.mentaleye.biz.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.TimeTableClassBean;
import com.mentaleye.biz.TimeTableClassBiz;
import com.mentaleye.dal.model.TimeTableClassExample;
import com.mentaleye.dal.model.TimeTableClassKey;
import com.mentaleye.service.TimeTableClassService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;

@Service
public class TimeTableClassBizImpl implements TimeTableClassBiz{

	@Autowired private TimeTableClassService timeTableClassService;
	
	private static Logger logger = Logger.getLogger(TimeTableClassBizImpl.class);
	
	public CommonResult addTimeTableClass(TimeTableClassBean timeTableClassBean){
		CommonResult result = new CommonResult();
		boolean success = false;
		try {
			success = timeTableClassService.addTimeTableClass(timeTableClassBean);
			result.setIsSuccess(success);
		} catch (Exception e) {
			logger.error("班级课表添加异常", e);
		}
		return result;
	}
	
	public CommonResult modifyTimeTableClass(TimeTableClassBean timeTableClassBean){
		CommonResult result = new CommonResult();
		boolean success = false;
		try {
			success = timeTableClassService.updateTimeTableClass(timeTableClassBean);
			result.setIsSuccess(success);
		} catch (Exception e) {
			logger.error("班级课表修改异常", e);
		}
		return result;
	}
	
	public CommonResult removeTimeTableClass(int timeTableId,int oaClassId){
		CommonResult result = new CommonResult();
		boolean success = false;
		try {
			success = timeTableClassService.deleteTimeTableClass(timeTableId, oaClassId);
			result.setIsSuccess(success);
		} catch (Exception e) {
			logger.error("班级课表删除异常", e);
		}
		return result;
	}
	
	public CommonResult removeTimeTableClassList(List<TimeTableClassKey> keylist){
		CommonResult result = new CommonResult();
		boolean success = false;
		try {
			success = timeTableClassService.deleteTimeTableClassList(keylist);
			result.setIsSuccess(success);
		} catch (Exception e) {
			logger.error("班级课表批量删除异常", e);
		}
		return result;
	}
	
	public TimeTableClassBean queryTimeTableClass(int timeTableId,int oaClassId){
		TimeTableClassBean result = null;
		try {
			result = timeTableClassService.queryTimeTableClassByKey(timeTableId, oaClassId);
		} catch (Exception e) {
			logger.error("班级课表查询异常", e);
		}
		return result;
	}
	
	public List<TimeTableClassBean> queryTimeTableClassByExample(TimeTableClassExample example){
		List<TimeTableClassBean> result = null;
		try {
			result = timeTableClassService.queryTimeTableClassByExample(example);
		} catch (Exception e) {
			logger.error("班级课表条件查询异常", e);
		}
		return result;
	}

	@Override
	public TimeTableClassBean queryTimeTableClassByOaClassId(Integer oaClassId){
		TimeTableClassBean result = null;
		try {
			TimeTableClassExample example = new TimeTableClassExample();
			example.createCriteria().andOaClassIdEqualTo(oaClassId);
			List<TimeTableClassBean> timeTableClass = timeTableClassService.queryTimeTableClassByExample(example);
			for (TimeTableClassBean bean:timeTableClass) {
				result = bean;
			}
		} catch (Exception e) {
			logger.error("根据班级编号查询课表异常", e);
		}
		return result;
	}
	
	public void queryByMap(CommonPage commonPage){
		timeTableClassService.queryByMap(commonPage);
	}
}
